package com.mallorcamaus.productlist.app;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import android.view.View.OnClickListener;


public class CategoryListActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.categorylist);
        
        isMobileConnected();
        
        ImageView hotelImg = (ImageView)findViewById(R.id.imageViewHotel); 
        hotelImg.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (isMobileConnected()) {
					Intent hotelIntent = new Intent(v.getContext(), HotelListActivity.class);
					startActivity(hotelIntent);
				}
			}
		});
        
        ImageView eventsImg = (ImageView)findViewById(R.id.imageViewEvents); 
        eventsImg.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (isMobileConnected()) { 
					Intent eventIntent = new Intent(v.getContext(), EventListActivity.class);
					startActivity(eventIntent);
				}
			}
		});
        
        
        /* dummy fur hochzeiten, da gibts noch kein json */
        
        ImageView restaurantsImg = (ImageView)findViewById(R.id.imageViewRestaurants); 
        restaurantsImg.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (isMobileConnected()) {
					Intent restaurantsIntent = new Intent(v.getContext(), RestaurantListActivity.class);
					startActivity(restaurantsIntent);
				}
			}
		});
        
        ImageView yachtenImg = (ImageView)findViewById(R.id.imageViewYachten); 
        yachtenImg.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (isMobileConnected()) {
					Intent yachtenIntent = new Intent(v.getContext(), YachtenListActivity.class);
					startActivity(yachtenIntent);
				}
			}
		});
    }
    
    /**
     * Checks with ConnectivityManager if connection with WIFI or MOBILE is connected, if not connected make Toast text
     * @return boolean is connected or not
     */
    private boolean isMobileConnected() {
    	ConnectivityManager cm = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
		if (!cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected() && !cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
			Toast.makeText(this, getString(R.string.not_connected), Toast.LENGTH_SHORT).show();
			return false;
		} else {
			return true;
		}	
    }
}